<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<h2>0</h2>
<script>
  let count = 0;
  //定时器
  let timer = setInterval(f,1000);
  function f() {
    count++;
      let h = document.querySelector("h1");
      h.innerText = count;
      if (count == 5){
        //clearInterval()停止计时器
        clearInterval(timer);
      }
  }
  let num = 0;
  let time = setInterval(function (){
    num++;
    let h = document.querySelector("h2");
    h.innerText = num;
    if (num==50){
      clearInterval(time);
    }
  },100)

  //只执行一次的定时器
  setTimeout(function (){
    alert("时间到！")
  },3000)
</script>
</body>
</html>